package com.ruoyi.jjyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jjyh.domain.JjyhMemberlevel;
import com.ruoyi.jjyh.service.IJjyhMemberlevelService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员级别Controller
 * 
 * @author ruoyi
 * @date 2020-11-19
 */
@Controller
@RequestMapping("/jjyh/memberlevel")
public class JjyhMemberlevelController extends BaseController
{
    private String prefix = "jjyh/memberlevel";

    @Autowired
    private IJjyhMemberlevelService jjyhMemberlevelService;

    @RequiresPermissions("jjyh:memberlevel:view")
    @GetMapping()
    public String memberlevel()
    {
        return prefix + "/memberlevel";
    }

    /**
     * 查询会员级别列表
     */
    @RequiresPermissions("jjyh:memberlevel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JjyhMemberlevel jjyhMemberlevel)
    {
        startPage();
        List<JjyhMemberlevel> list = jjyhMemberlevelService.selectJjyhMemberlevelList(jjyhMemberlevel);
        return getDataTable(list);
    }

    /**
     * 导出会员级别列表
     */
    @RequiresPermissions("jjyh:memberlevel:export")
    @Log(title = "会员级别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JjyhMemberlevel jjyhMemberlevel)
    {
        List<JjyhMemberlevel> list = jjyhMemberlevelService.selectJjyhMemberlevelList(jjyhMemberlevel);
        ExcelUtil<JjyhMemberlevel> util = new ExcelUtil<JjyhMemberlevel>(JjyhMemberlevel.class);
        return util.exportExcel(list, "memberlevel");
    }

    /**
     * 新增会员级别
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存会员级别
     */
    @RequiresPermissions("jjyh:memberlevel:add")
    @Log(title = "会员级别", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JjyhMemberlevel jjyhMemberlevel)
    {
        return toAjax(jjyhMemberlevelService.insertJjyhMemberlevel(jjyhMemberlevel));
    }

    /**
     * 修改会员级别
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JjyhMemberlevel jjyhMemberlevel = jjyhMemberlevelService.selectJjyhMemberlevelById(id);
        mmap.put("jjyhMemberlevel", jjyhMemberlevel);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员级别
     */
    @RequiresPermissions("jjyh:memberlevel:edit")
    @Log(title = "会员级别", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JjyhMemberlevel jjyhMemberlevel)
    {
        return toAjax(jjyhMemberlevelService.updateJjyhMemberlevel(jjyhMemberlevel));
    }

    /**
     * 删除会员级别
     */
    @RequiresPermissions("jjyh:memberlevel:remove")
    @Log(title = "会员级别", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jjyhMemberlevelService.deleteJjyhMemberlevelByIds(ids));
    }
}
